﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 二分查找._367.有效的完全平方数
{
    class MainProject
    {
        static void Main(string[] args)
        {
            Console.WriteLine(IsPerfectSquare(16));
            Console.ReadKey();
        }

        public static bool IsPerfectSquare(int num)
        {
            //时间复杂度  O log(n)   空间 O(1)  
            long left = 1, right = num;
            while (left <= right)
            {
                long mid = left + ((right - left) >> 1);
                long res = mid * mid;
                if (res == num) return true;
                else if (res > num) right = mid - 1;
                else left = mid + 1;
            }
            return false;
        }
    }
}
